import requests
from urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
import re

Platform = "微小宝"


def weixiaobao():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        url = "https://account.wxb.com/login?from=http%3A%2F%2Fxs.wxb.com%2Findex"
        data = {
            "email": "",
            "password": "",
            "captcha": "",
            "from": "http://xs.wxb.com/index"
        }
        header = {
            "referer": "https://account.wxb.com/?from=http%3A%2F%2Fxs.wxb.com%2Findex",
            "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",
            "x-requested-with": "XMLHttpRequest"
        }
        rr = r.post(url=url, data=data, headers=header, verify=False, timeout=15)
        aa = r.get(url="http://xs.wxb.com/collect", verify=False, timeout=15)
        html = aa.text.replace('\r', '').replace('\t', '').replace('\n', '')
        date_time_list = re.findall('<tbody.*?<tr.*?<tr.*?<span.*?</span><!--.*?<!--.*?>(.*?)<!.*?</td>', html)
        date_time = date_time_list[0]
        Amount_share_list = re.findall('<tbody.*?<tr.*?<tr.*?<td.*?<td.*?<!--.*?>(.*?)<!.*?</td>', html)
        Amount_share = round(int(Amount_share_list[0]) * 0.9, 2)
        return date_time, Amount_share, Platform
    except Exception:
        print("获取 微小宝 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 微小宝 数据 超时")
        return '', 'None', Platform